package org.smog.web;

import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.smog.core.config.security.BaseSecurityController;
import org.smog.core.config.security.model.JwtToken;
import org.smog.service.auth.IAuthService;
import org.smog.service.auth.dto.AuthInput;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @Description: Created by IntelliJ IDEA.
 * @project_name: smogTemp
 * @time: 2020-05-14 15:43
 * @email: 17685306043@163.com
 * @author: huangZhongYao
 */
@Api(tags = "认证模块")
@RestController
@RequestMapping("/auth")
@AllArgsConstructor
public class AuthController extends BaseSecurityController {

	IAuthService authService;

	@ApiOperation(value = "获取登录token", notes = "获取登录token")
	@ApiResponses({
			@ApiResponse(code = 200, message = "正常")
	})
	@ApiImplicitParams({
			@ApiImplicitParam(name = "Authenticate", required = false)
	})
	@PostMapping("/token")
	@PreAuthorize("permitAll")
	public JwtToken login(@Valid @RequestBody AuthInput input) {
		return authService.login(input);
	}


	@ApiOperation(value = "退出登录", notes = "退出登录")
	@ApiResponses({
			@ApiResponse(code = 200, message = "正常")
	})
	@PostMapping("/logout")
	@PreAuthorize("isAuthenticated()")
	public Boolean logout() {
		return authService.logout();
	}
}
